package soccerscope.view;

import java.awt.event.ActionEvent;

import javax.swing.JTextField;

/**
 * Allows to jump to a concrete Cycle number.
 * 
 * @author benjaboe
 * 
 */
public class CycleNumberJumper
    extends AbstractSceneJumper {

  private static final long serialVersionUID = -6640906520407436537L;

  /** InputField to enter the cycle number. */
  private JTextField        timeField;

  /**
   * Creates a new Button and TextField for choose and jump to cycle
   * 
   * @param scenePlayer
   *          the ScenePlayer to jump to the cycle
   */
  public CycleNumberJumper(
      ScenePlayer scenePlayer) {

    super(scenePlayer);
    this.timeField = new JTextField("0", 5);
    this.add(this.timeField);
  }

  /**
   * is called when the jump button was pressed. Jumps to the scene which number
   * is written in timeField
   */
  public void actionPerformed(ActionEvent arg0) {

    int number;
    try {
      number = Integer.parseInt(this.timeField.getText());
    }
    catch (NumberFormatException e) {
      return;
    }
    this.jumpToCycle(number);
  }

}
